package com.android.jay.lib_network.okhttp_learn;

import com.android.jay.lib_network.okhttp.ssl.HttpUtils;
import com.android.jay.lib_network.okhttp_learn.listener.DisposeDataHandle;

import java.util.concurrent.TimeUnit;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;

import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;

/**
 * Created by wzp on 2020/3/1 0001.
 * <p>
 * 描述  ：todo
 */
public class CommonOkhttpClient {

    private static final int TIME_OUT = 30;
    private static OkHttpClient commonOkhttpClient;


    static {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();

        builder.hostnameVerifier(new HostnameVerifier() {
            @Override
            public boolean verify(String s, SSLSession sslSession) {
                return true;
            }
        });

        builder.connectTimeout(TIME_OUT, TimeUnit.SECONDS);
        builder.readTimeout(TIME_OUT, TimeUnit.SECONDS);
        builder.writeTimeout(TIME_OUT,TimeUnit.SECONDS);
        //重定向
        builder.followRedirects(true);
        builder.sslSocketFactory(HttpUtils.getSslSocketFactory());
        commonOkhttpClient = builder.build();
    }


    public static void post(Request request, DisposeDataHandle handle){

        Call call = commonOkhttpClient.newCall(request);
        call.enqueue(new CommonCallBack(handle));

    }

    public static void get(Request request, DisposeDataHandle handle){

        Call call = commonOkhttpClient.newCall(request);
        call.enqueue(new CommonCallBack(handle));

    }

    ///文件下载


}
